package cn.com.dhcc.turbo.web.controller.stat;

 
import java.util.List;
import java.util.Map;
 
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.dhcc.app.core.base.BaseController; 
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu.LEAF_MENU;  
import cn.com.dhcc.turbo.entity.registry.AdapterInfo;
import cn.com.dhcc.turbo.entity.stat.ExchStatManage;
import cn.com.dhcc.turbo.service.registry.AdapterInfoService;
import cn.com.dhcc.turbo.service.stat.ExchStatManageService;

@Controller
@RequestMapping("/stat")
@TurboMenu(belongToMenu = LEAF_MENU.EXCH_MANAGE)
public class ExchStatManageController extends BaseController {
	@SuppressWarnings("deprecation")
	Logger logger = Log.getExistLogger(LOGTYPE.R);
	  @Autowired
	  ExchStatManageService service;
	  @Autowired
		AdapterInfoService adapterService;
	/**
	 * 
	 * @param model 
	 * @return
	 */
	
	@RequestMapping(value = "/exch_total_manage")
	public String exchTotalManage(Model model) {  
		try {  
			List<ExchStatManage> nodeInfos=service.getNodeInfos(); 
			List<AdapterInfo> adapterList = adapterService.getLocalAdapterList();
			List<AdapterInfo> relAdapterList = adapterService.getRelNodeAdapterList();
		   model.addAttribute("nodeList", nodeInfos);
		   model.addAttribute("adapterList", adapterList);
		   model.addAttribute("relAdapterList", relAdapterList);
			
		} catch (Exception e) {
			logger.error("操作失败", e);
		 
		}
		return "stat/exch_total_manage";
	}
	
	/**
	 * @param mtime ,统计时间.
	 * @return
	 */

	@RequestMapping(value = "/st_bt_reg_y")
	@ResponseBody
	public Map<String, Object> getStBtReg(String nt,Model model) {
		String msg="";
		try {
		 msg=service.getStBtReg(nt);
		 return jsonSuccessDataResult("success", msg);
		} catch (ServiceException e) {
			msg = "日志统计失败";
			logger.error(msg, e);
			return jsonFailResult(msg);
		} 
	}
	/**
	 * 节点间交换频率(月/年)
	 * @param mtime 统计时间
	 * @param stat_level 统计级别： 1 节点  3 系统
	 * @param timeType
	 * @return 
	 */ 

	@RequestMapping(value = "/st_bt_node_num")
	@ResponseBody
	public Map<String, Object> getStBtNodeNum(String nt,String timeType,String stat_level, Model model) {
		String msg="";
		try {
		 msg=service.getStBtNodeNum(nt, timeType, stat_level );
		 return jsonSuccessDataResult("success", msg);
		} catch (ServiceException e) {
			msg = "日志统计失败";
			logger.error(msg, e);
			return jsonFailResult(msg);
		}
	}
	
 
	
	/**
	 * 内外网交换频率最高的业务数据（月/年）
	 * @param mtime 统计时间
	 * @param stat_level 统计级别： 1 节点 2 业务域 3 系统
	 * @param timeType
	 * @return 
	 */ 

	@RequestMapping(value = "/st_bt_net_top")
	@ResponseBody
	public Map<String, Object> getStBtNetTop(String nt,String timeType,String stat_level, Model model) {
		String msg="";
		try {
		 msg=service.getStBtNetTop(nt, timeType, stat_level);
		 return jsonSuccessDataResult("success", msg);
		} catch (ServiceException e) {
			msg = "日志统计失败";
			logger.error(msg, e);
			return jsonFailResult(msg);
		} 
	}
	
 
	/**
	 * 交换频率最高的业务数据 
	 * */
	@RequestMapping(value = "/st_bt_dt_top")
	@ResponseBody
	public Map<String, Object> getStBtDtTop(String nt,String timeType,String stat_level,String to_node_id,String from_node_id,Model model) {
		String msg="";
		try {
		 msg=service.getStBtDtTop(nt, timeType, to_node_id, from_node_id, stat_level);
		 return jsonSuccessDataResult("success", msg);
		} catch (ServiceException e) {
			msg = "日志统计失败";
			logger.error(msg, e);
			return jsonFailResult(msg);
		} 
	}
	
 

	 
}
